//
//  UTEWeekType.swift
//  Kosspot
//
//  Created by 李鑫 on 2025/7/23.
//

import Foundation
import UTEBluetoothRYApi

enum UTEWeekType: Int {
    case UTEWeekTypeMon  = 0x01 // 1
    case UTEWeekTypeTue  = 0x02 // 2
    case UTEWeekTypeWed  = 0x04 // 4
    case UTEWeekTypeThur = 0x08 // 8
    case UTEWeekTypeFri  = 0x10 // 16
    case UTEWeekTypeSat  = 0x20 // 32
    case UTEWeekTypeSun  = 0x40 // 64
    static func getWeekdayNames(from rawValue: Int) -> [String] {
        let mapping: [UTEWeekType: String] = [
            .UTEWeekTypeMon: "周一",
            .UTEWeekTypeTue: "周二",
            .UTEWeekTypeWed: "周三",
            .UTEWeekTypeThur: "周四",
            .UTEWeekTypeFri: "周五",
            .UTEWeekTypeSat: "周六",
            .UTEWeekTypeSun: "周日"
        ]
        let cycles = mapping.filter { rawValue & $0.key.rawValue != 0 }.map { $0.value }
        let weekdays = ["周日","周一", "周二", "周三", "周四", "周五", "周六"]
        var cycle:[String]
        if cycles.count == 0{
            cycle = ["一次"]
        } else if cycles.count == 7 {
            cycle = ["每天"]
        }else if cycles.count == 5 && !cycles.contains("周六") && !cycles.contains("周日"){
            cycle = ["工作日"]
        }else if cycles.count == 2 && cycles.contains("周六") && cycles.contains("周日"){
            cycle = ["周末"]
        }else {
            cycle = cycles.sorted { weekdays.firstIndex(of: $0)! < weekdays.firstIndex(of: $1)! }
        }
        return cycle
    }
    
    static func getWeekdayName(from rawValue: Int) -> [String] {
        let mapping: [UTEWeekType: String] = [
            .UTEWeekTypeMon: "周一",
            .UTEWeekTypeTue: "周二",
            .UTEWeekTypeWed: "周三",
            .UTEWeekTypeThur: "周四",
            .UTEWeekTypeFri: "周五",
            .UTEWeekTypeSat: "周六",
            .UTEWeekTypeSun: "周日"
        ]
        return  mapping.filter { rawValue & $0.key.rawValue != 0 }.map { $0.value }
    }
}
